<template>
	<view class="container">
		<view class="list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">头像</text>
			<image class="head_img" :mode="widthFix" :src="avatar || '/static/missing-face.png'" @tap="uploadTap"></image>
		</view>
		<view class="list-cell b-b m-t" @click="navTo('修改昵称', 'nickname')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">修改昵称</text>
			<text>{{arrList.nickname}}<text class="cell-more yticon icon-you"></text></text>
		</view>
		<view class="list-cell b-b" @click="navTo1('/pages/public/changePwd')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">修改密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b m-t" @click="navTo1('/pages/set/bindCard')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">绑定银行卡</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b m-t" @click="navTo1('/pages/set/myCode')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">我的二维码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b m-t" @click="navTo1('/pages/set/moneyCode')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">提现收款码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<!-- <view class="list-cell b-b" @click="navTo1('/pages/set/changePhone')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">更换手机号</text>
			<text class="cell-more yticon icon-you"></text>
		</view> -->
		<prompt :title="title" @submit="submit" v-model="popShow"></prompt>
	</view>
	
</template>

<script>
	import {  
	    mapMutations, mapActions, mapState
	} from 'vuex';
	import prompt from './child/prompt'
	export default {
		components: {
			prompt
		},
		data() {
			return {
				popShow: false,
				title: '',
				key: '',
				tempFilePaths: "",
				alipayimg: "",
				img_hight:"",
				mod:false,
				widthFix: '',
				arrList:[],
				avatar:''
			};
		},
		created() {
		  // let that = this
		  // uni.getStorage({
		  //   key: 'know',
		  //   success: function(res) {
		  //     // console.log(res.data);
		  //     let shju = JSON.parse(res.data)
		  //     that.phone = shju.mobile
						
				// 		var img_url  =that.touxiang
				// 		var img = new Image()
				// 		img.src = img_url
				// 		console.log(img.complete)
				// 		  if( img.complete ){
				// 		    console.log(img.width+" "+img.height);
								
				// 		  }else{
				// 		    img.onload = function(){
				// 		      console.log(img.width+" "+img.height);
				// 					that.img_hight = (480*img.height)/img.width+'upx';
				// 		      img.onload=null;
				// 					console.log(that.img_hight)
				// 		      }
				// 		  }
						
						
						
		  //   },
		  //   fail: function(res) {
		  //     // console.log(res)
		  //     uni.reLaunch({
		  //       url: '/pages/public/login',
		  //     })
		  //   }
		  // });
		},
		computed: {
			...mapState({
				userinfo: state => state.user.userinfo
			}),
			hasLogin() {
				return this.userinfo.id ? true : false
			}
		},
		onLoad(option) {
			this.initDat();//初始化数据
		},
		methods:{
			...mapMutations(['SAVE_USERINFO']),
			navTo(title, key){
				this.title = title
				this.key = key
				this.popShow = true
			},
			navTo1(url){
				if(!this.userinfo.id){
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},
			submit(val) {
				let form = {}
				form[this.key] = val
				this.$http.post('user.info.edit', form).then(res => {
					this.popShow = false;
					this.initDat();//初始化数据
					uni.showToast({
						title: '修改成功'
					})
					this.SAVE_USERINFO(res.data)
				})
			},
			uploadTap() {
				let that = this
				uni.chooseImage({
				  count: 1, //默认9
				  sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				  sourceType: ['album'],
				  success: (chooseImageRes) => {
				    that.tempFilePaths = chooseImageRes.tempFilePaths;
				
				    uni.uploadFile({
				      url: this.$common.baseUrl + '/api/common/upload', //上传接口地址
				      filePath: that.tempFilePaths[0],
				      name: 'file',
				      enctype: "multipart/form-data",
				      formData: {
				        mobile: that.phone
				      },
				        success: (uploadFileRes) => {
							let res = JSON.parse(uploadFileRes.data);
							// that.avatar = configs.baseUrl + res.data.url.substr(1);
							that.avatar = this.$common.baseUrl + res.data.url;
							uni.setStorageSync('avatar', that.avatar);
							// that.alipayimg = that.baseurl + "/service" + res.data.alipayimg
							this.$http.post('updateavatar',{avatar: res.data.url}).then(res => {
								this.$api.msg(res.msg);							
							})
							
						}
				    });
				
				  }
				});
		},
		//初始化数据
		initDat(){
			let that = this
			this.$http.post('shezhiuserinfo').then(res => {
				this.arrList = res.data;
				this.avatar = res.data.avatar;
				uni.setStorageSync('avatar', this.avatar);
			})
		}
	},
	}
</script>

<style lang='scss'>
	page{
		background: $page-color-base;
	}
	.list-cell{
		display:flex;
		align-items:baseline;
		padding: 20upx $page-row-spacing;
		line-height:60upx;
		position:relative;
		background: #fff;
		justify-content: center;
		align-items: center;
		&.log-out-btn{
			margin-top: 40upx;
			.cell-tit{
				color: $uni-color-primary;
				text-align: center;
				margin-right: 0;
			}
		}
		&.cell-hover{
			background:#fafafa;
		}
		&.b-b:after{
			left: 30upx;
		}
		.cell-more{
			align-self: baseline;
			font-size:$font-lg;
			color:$font-color-light;
			margin-left:10upx;
		}
		.cell-tit{
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right:10upx;
		}
		.cell-tip{
			font-size: $font-base;
			color: $font-color-light;
		}
		switch{
			transform: translateX(16upx) scale(.84);
		}
	}
	.head_img{
		width: 90upx;
		height: 90upx;
		border-radius: 50%;
	}
</style>
